package com.astoolkit.onair.workflow
{
	import com.astoolkit.workflow.core.BaseTask;
	
	import com.astoolkit.onair.RunnableModuleEvent;
	import com.astoolkit.onair.api.IRunnable;
	
	import mx.core.FlexGlobals;
	
	[TaskInput("com.astoolkit.onair.api.IRunnable")]
	public class RunModuleTask extends BaseTask
	{
		
		[InjectPipeline]
		public var module : IRunnable;
		
		override public function begin() : void
		{
			super.begin();
			if( !module ) 
			{
				fail( "No module in the pipeline" );
				return;
			}
			if( module.config.runOnStartup )
			{
				if( module.run() )
					complete();
				else
				{
					module.addEventListener( RunnableModuleEvent.INITIALIZED, onModuleInitialized );
					
				}
			}
			else
				complete();
			
		}
		
		private function onModuleInitialized( inEvent : RunnableModuleEvent ) : void
		{
			complete();
		}

	}
}